home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et-2_2.lha / et2.2 / src / SERVER / ServerPort.C < prev    next >
C/C++ Source or Header  |  1990-11-21  |  5KB  |  254 lines

  1. #include "ServerPort.h"
  2. #include "Error.h"
  3. #include "String.h"
  4. #include "ServerFont.h"
  5. #include "ServerBitmap.h"
  6.  
  7. #include "ServerConnection.h"
  8.  
  9. static byte *tblist, *tbcp;
  10. static FontPtr lastfdp= 0;
  11.  
  12. //------------------------------------------------------------------------------
  13.  
  14. ServerPort::ServerPort(InpHandlerFun nf, void *priv1, bool ov, bool bl)
  15.     : WindowPort (nf, priv1, ov, bl, 0)
  16. {    
  17.     gConnection->SendMsg(eMsgMakeWindow, -1, "ssiI", ov, bl, (int)this, &ref);
  18.     out= 1;
  19.     in= MQS;
  20.     
  21.     if (tblist == 0)
  22.     tbcp= tblist= new byte[MaxTextBatchCnt];
  23. }
  24.  
  25. void ServerPort::DevDestroy2()
  26. {
  27.     gConnection->SendMsg(eMsgDestroy, ref);
  28.     gConnection->Flush();
  29. }
  30.  
  31. void ServerPort::DevClip(Rectangle r, Point p)
  32. {
  33.     gConnection->SendMsg(eMsgClip, ref, "rp", &r, &p);
  34. }
  35.  
  36. void ServerPort::DevResetClip()
  37. {
  38.     gConnection->SendMsg(eMsgResetClip, ref);
  39. }
  40.  
  41. void ServerPort::DevStrokeLine(Ink pat, int ps, Rectangle *r,
  42.                     GrLineCap cap, Point p1, Point p2)
  43. {
  44.     gConnection->SendMsg(eMsgStrokeLine, ref, "ssppir", pat, cap, &p1, &p2, ps, r);
  45. }
  46.  
  47. void ServerPort::DevStrokeRect(Ink pat, int ps, Rectangle *r)
  48. {
  49.     gConnection->SendMsg(eMsgStrokeRect, ref, "sri", pat, r, ps);
  50. }
  51.  
  52. void ServerPort::DevFillRect(Ink pat, Rectangle *r)
  53. {
  54.     gConnection->SendMsg(eMsgFillRect, ref, "sr", pat, r);
  55. }
  56.  
  57. void ServerPort::DevStrokeRRect(Ink pat, int ps, Rectangle *r, Point dia)
  58. {
  59.     gConnection->SendMsg(eMsgStrokeRRect, ref, "srip", pat, r, ps, &dia);
  60. }
  61.  
  62. void ServerPort::DevFillRRect(Ink pat, Rectangle *r, Point dia)
  63. {
  64.     gConnection->SendMsg(eMsgFillRRect, ref, "srp", pat, r, &dia);
  65. }
  66.  
  67. void ServerPort::DevStrokeOval(Ink pat, int ps, Rectangle *r)
  68. {
  69.     gConnection->SendMsg(eMsgStrokeOval, ref, "sri", pat, r, ps);
  70. }
  71.  
  72. void ServerPort::DevFillOval(Ink pat, Rectangle *r)
  73. {
  74.     gConnection->SendMsg(eMsgFillOval, ref, "sr", pat, r);
  75. }
  76.  
  77. void ServerPort::DevStrokeWedge(Ink pat, int ps, GrLineCap cap,
  78.                         Rectangle *r, int s, int l)
  79. {
  80.     Point p(s,l);
  81.     gConnection->SendMsg(eMsgStrokeWedge, ref, "sisrp", pat, ps, cap, r, &p);
  82. }
  83.  
  84. void ServerPort::DevFillWedge(Ink pat, Rectangle *r, int s, int l)
  85. {
  86.     Point p(s,l);
  87.     gConnection->SendMsg(eMsgFillWedge, ref, "srp", pat, r, &p);
  88. }
  89.  
  90. void ServerPort::DevStrokePolygon(Rectangle*, Ink, Point*, int, GrPolyType, int, GrLineCap)
  91. {
  92. }
  93.  
  94. void ServerPort::DevFillPolygon(Rectangle*, Ink, Point*, int, GrPolyType)
  95. {
  96. }
  97.  
  98. void ServerPort::DevShowBitmap(Ink pat, Rectangle *r, Bitmap *bm)
  99. {
  100.     gConnection->SendMsg(eMsgShowBitmap, ref, "sri", pat, r,
  101.                         ((ServerBitmap*)bm)->GetId());
  102. }
  103.  
  104. bool ServerPort::DevShowChar(FontPtr fdp, Point delta, byte c, bool isnew, Point)
  105. {
  106.     if (isnew) {
  107.     tbcp= tblist;
  108.     lastfdp= 0;
  109.     }
  110.     
  111.     if (tbcp-tblist >= MaxTextBatchCnt-15)
  112.     return TRUE;
  113.     
  114.     if (fdp != lastfdp) {
  115.     *tbcp++= '#';
  116.     *tbcp++= 'f';
  117.     *tbcp++= (byte) ((ServerFont*)fdp)->GetId();
  118.     lastfdp= fdp;
  119.     }
  120.     if (delta.x) {
  121.     short d= delta.x;
  122.     *tbcp++= '#';
  123.     *tbcp++= 'x';
  124.     *tbcp++= d >> 8;
  125.     *tbcp++= d & 0xff;
  126.     }
  127.     if (delta.y) {
  128.     short d= delta.y;
  129.     *tbcp++= '#';
  130.     *tbcp++= 'y';
  131.     *tbcp++= d >> 8;
  132.     *tbcp++= d & 0xff;
  133.     }
  134.     if (c == '#')
  135.     *tbcp++= '#';
  136.     *tbcp++= c;
  137.     return FALSE;
  138. }
  139.  
  140. void ServerPort::DevShowTextBatch(Ink pat, Rectangle *r, Point pos)
  141. {
  142.     gConnection->SendMsg(eMsgShowTextBatch, ref, "srpb", pat, r, &pos,
  143.                             (int)(tbcp-tblist), tblist);
  144. }
  145.  
  146. void ServerPort::DevGiveHint(int code, int len, void *vp)
  147. {
  148.     switch (code) {
  149.     case eHintTextBatch:
  150.     case eHintTextUnbatch:
  151.     case eHintLock:
  152.     case eHintUnlock:
  153.     return;
  154.     case eHintFlush:
  155.     break;
  156.     default:
  157.     gConnection->SendMsg(eMsgGiveHint, ref, "sb", code, len, vp);
  158.     }
  159.     gConnection->Flush();
  160. }
  161.  
  162. void ServerPort::DevScrollRect(Rectangle r, Point p)
  163. {
  164.     gConnection->SendMsg(eMsgScrollRect, ref, "rpZ", &r, &p);
  165. }
  166.  
  167. void ServerPort::DevTop(bool top)
  168. {
  169.     gConnection->SendMsg(eMsgTop, ref, "sZ", top);
  170. }
  171.  
  172. void ServerPort::DevHide()
  173. {
  174.     gConnection->SendMsg(eMsgHide, ref);
  175. }
  176.  
  177. void ServerPort::DevShow(WindowPort *father, Rectangle r)
  178. {
  179.     gConnection->SendMsg(eMsgShow, ref, "ir",
  180.                 father ? ((ServerPort*)father)->ref : -1, &r);
  181. }
  182.  
  183. void ServerPort::DevSetRect(Rectangle *r)
  184. {
  185.     gConnection->SendMsg(eMsgSetRect, ref, "r", r);
  186. }
  187.  
  188. inline int addone(int i)
  189. {
  190.     return (i % MQS) + 1;
  191. }
  192.  
  193. void ServerPort::Enqueue(Response *rp)
  194. {
  195.     if (addone(addone(in)) != out) {
  196.     in= addone(in);
  197.     rps[in]= *rp;
  198.     }    
  199. }
  200.  
  201. Response *ServerPort::Dequeue()
  202. {
  203.     Response *r;
  204.     
  205.     if (addone(in) == out)
  206.     return 0;
  207.     r= &rps[out];
  208.     out= addone(out);
  209.     return r;
  210. }
  211.    
  212. void ServerPort::DevGetEvent(Token *t, int timeout, bool overread)
  213. {
  214.     Response *r, rp;
  215.     bool first= overread;
  216.     
  217. //    do {
  218.     while ((r= Dequeue()) == 0) {
  219.         if (gConnection->SafeRead(&rp, timeout, overread)) {
  220.         if (first || ! overread) {
  221.             t->Code= eEvtNone;
  222.             t->Flags= 0;
  223.             return;
  224.         }
  225.         }
  226.         if (rp.port)
  227.         ((ServerPort*)rp.port)->Enqueue(&rp);
  228.         first= FALSE;
  229.     }
  230. //    } while (r->port == 0);
  231.     
  232.     *t= r->t;
  233. };
  234.  
  235. void ServerPort::DevGrab(bool on, bool fullscreen)
  236. {
  237.     gConnection->SendMsg(eMsgGrab, ref, "ss", on, fullscreen);
  238. }
  239.     
  240. void ServerPort::DevSetMousePos(Point p, bool m)
  241. {
  242.     gConnection->SendMsg(eMsgSetMousePos, ref, "ps", &p, (short) m);
  243. };
  244.  
  245. void ServerPort::DevBell(long d)
  246. {
  247.     gConnection->SendMsg(eMsgBell, ref, "i", (int) d);
  248. }
  249.  
  250. void ServerPort::DevSetCursor(GrCursor c)
  251. {
  252.     gConnection->SendMsg(eMsgSetCursor, ref, "s", (short) c);
  253. }
  254.